package com.luoc;

import com.luoc.entity.User;
import com.luoc.mapper.DemoMapper;
import com.mybatis.session.SqlSession;
import com.mybatis.session.SqlSessionFactory;
import com.mybatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.List;

/**
 * @author luoc
 * @version 1.0
 * @date 2021/2/20 13:50
 * @since 1.0
 */
public class testMybatis {

    public static void main(String[] args) {
        String resource = "Mybatis-config.xml";

        InputStream inputStream = testMybatis.class.getClassLoader().getResourceAsStream(resource);
        SqlSessionFactoryBuilder builder =  new SqlSessionFactoryBuilder();
        SqlSessionFactory sqlSessionFactory = builder.build(inputStream);
        System.out.println(sqlSessionFactory);
        System.out.println(sqlSessionFactory.getConfiguration().getJdbcProperties().getUrl());

        SqlSession sqlSession = sqlSessionFactory.openSqlSession();

        List<User> a = sqlSession.selectList("com.luoc.mapper.DemoMapper.selectAll");
        System.out.println(a);


       DemoMapper demoMapper =  sqlSession.getMapper(DemoMapper.class);
        System.out.println(demoMapper.selectAll());

    }
}
